<template>
  <!-- 面包屑导航区域 -->
  <el-breadcrumb separator-icon="ArrowRight">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
      <el-breadcrumb-item>用户列表</el-breadcrumb-item>
  </el-breadcrumb>
  <!-- 卡片区域 -->
  <el-card>
    <el-row :gutter="20">
      <el-col :span="9">
        <!-- 搜索与添加区域 -->
        <el-input placeholder="请输入内容" v-model="queryInfo.username">
            <template #append>
              <el-button icon="Search" @click="getUsersList" class="searchUser"></el-button>
            </template>
        </el-input>
      </el-col>
      <el-col :span="4">
          <el-button type="primary" @click="addNewUser">新增用户</el-button>
      </el-col>
    </el-row>
    <!-- 用户列表区域 -->
    <el-table :data="userList" border stripe style="width: 100%">
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column label="姓名" prop="username"></el-table-column>
        <el-table-column label="邮箱" prop="email"></el-table-column>
        <el-table-column label="电话" prop="mobile"></el-table-column>
        <el-table-column label="角色" prop="roleName"></el-table-column>
        <el-table-column label="状态">
          <template #default="scope">
              <el-switch
                v-model="scope.row.userStatusBoolean"
                @change="userStateChanged(scope.row)"
                style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
              />
          </template>
        </el-table-column>
        <el-table-column label="操作" width="220">
          <template #default="scope">
            <el-button type="primary" size="small" @click="handleEdit(scope.$index, scope.row)">
              编辑
            </el-button>
            <el-button
              size="small"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
            >
              删除
            </el-button>
           <el-button
              size="small"
              type="success"
              @click="handleDelete(scope.$index, scope.row)"
            >
              分配角色
            </el-button>
          </template>
        </el-table-column>
    </el-table>
  </el-card>
</template>

<script setup lang="ts">
import { reactive } from "vue"

const userList = reactive([
  {
    username: 'laoli',
    email: '111111111@qq.com',
    mobile: '11111111111',
    roleName: 'devops',
    userStatus: 1,
    id: 1
  }, {
    username: 'laowang',
    email: '111111112@qq.com',
    mobile: '11111111112',
    roleName: 'dev',
    userStatus: 1,
    id: 2
  }, {
    username: 'laozhao',
    email: '111111113@qq.com',
    mobile: '11111111113',
    roleName: 'devLeader',
    userStatus: 1,
    id: 3
  }, {
    username: 'laoQi',
    email: '111111113@qq.com',
    mobile: '11111111114',
    roleName: 'devLeader',
    userStatus: 0,
    id: 4
  },
])
userList.forEach(v => {
  if (v.userStatus) v.userStatusBoolean = true;
  else v.userStatusBoolean = false;
})

const userStateChanged = (user) => {
}
const queryInfo = reactive({
  username: ''
})

const addNewUser = () => {

}

const getUsersList = () => {

}
</script>

<style scoped>
.el-breadcrumb {
  margin-bottom: 30px;
}
.el-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 30px;
}
.el-card {
  height: 600px;
}
</style>